#include <iostream>
#include <unistd.h>
#include <pthread.h>

// 新线程
void *run1(void *args)
{
    while (true)
    {
        std::cout << "new thread1, pid: " << getpid() << std::endl;
        std::cout << "new thread1, tid: " << pthread_self() << std::endl;

        sleep(1);
    }
    return nullptr;
}

void *run2(void *args)
{
    while (true)
    {
        std::cout << "new thread2, pid: " << getpid() << std::endl;
        std::cout << "new thread2, tid: " << pthread_self() << std::endl;

        sleep(1);
    }
    return nullptr;
}

int main()
{
    std::cout << "我是一个进程: " << getpid() << std::endl;
    pthread_t tid1;
    pthread_create(&tid1, nullptr, run1, (void *)"thread-1");
    pthread_t tid2;
    pthread_create(&tid2, nullptr, run2, (void *)"thread-1");

    // 主线程
    while (true)
    {
        std::cout << "main thread,tid: " << pthread_self() << std::endl;
        std::cout << "new thread1, tid: " << tid1 << std::endl;
        std::cout << "new thread2, tid: " << tid2 << std::endl;
        sleep(1);
    }

    return 0;
}